﻿using System;
using System.Collections.Generic;
using System.Text;
using Diablo3.Engine.Property;
using System.Xml.Serialization;

namespace Diablo3.Engine
{
    /// <summary>
    /// 装备
    /// </summary>
    [XmlInclude(typeof(AllResistance))]
    [XmlInclude(typeof(ArcaneHolyResistance))]
    [XmlInclude(typeof(Armor))]
    [XmlInclude(typeof(AttackSpeed))]
    [XmlInclude(typeof(AttackSpeedPercent))]
    [XmlInclude(typeof(BlockChance))]
    [XmlInclude(typeof(BlockValue))]
    [XmlInclude(typeof(ColdResistance))]
    [XmlInclude(typeof(CriticalHitChance))]
    [XmlInclude(typeof(CriticalHitDamage))]
    [XmlInclude(typeof(Damage))]
    [XmlInclude(typeof(DamagePercent))]
    [XmlInclude(typeof(DealtConvertedLife))]
    [XmlInclude(typeof(Dexterity))]
    [XmlInclude(typeof(FindingMagical))]
    [XmlInclude(typeof(FireResistance))]
    [XmlInclude(typeof(GoldfromMonsters))]
    [XmlInclude(typeof(Intelligence))]
    [XmlInclude(typeof(ItemsProperty))]
    [XmlInclude(typeof(LifePercent))]
    [XmlInclude(typeof(LifePerHit))]
    [XmlInclude(typeof(LifePerKill))]
    [XmlInclude(typeof(LifePerSecond))]
    [XmlInclude(typeof(LifeSteal))]
    [XmlInclude(typeof(LightningResistance))]
    [XmlInclude(typeof(MaxDamage))]
    [XmlInclude(typeof(MeleeDamageReduction))]
    [XmlInclude(typeof(MinDamage))]
    [XmlInclude(typeof(MissileDamageReduction))]
    [XmlInclude(typeof(PhysicalResistance))]
    [XmlInclude(typeof(PoisonResistance))]
    [XmlInclude(typeof(ShowDamage))]
    [XmlInclude(typeof(Strength))]
    [XmlInclude(typeof(Vitality))]
    public class Items : IAffecteDexterity, IAffecteIntelligence, IAffecteStrength, IAffecteVitality, IAffecteLifePercent, IAffecteArmor,
        IAffecteArcaneHolyResistance, IAffecteColdResistance, IAffecteFireResistance, IAffecteLightningResistance, IAffectePhysicalResistance, IAffectePoisonResistance,
        IAffecteBlockChance, IAffecteBlockValue, IAffecteMeleeDamageReduction, IAffecteMissileDamageReduction,
        IAffecteShowDamage, IAffecteMinDamage, IAffecteMaxDamage, IAffecteAttackSpeed, IAffecteAttackSpeedPercent, IAffecteCriticalHitChance, IAffecteCriticalHitDamage,
        IAffecteLifePerHit, IAffecteLifePerKill, IAffecteLifePerSecond, IAffecteLifeSteal
    {
        public Items()
        {
            _properties = new List<ItemsProperty>();
        }
        public Items(ItemsType type)
            : this()
        {
            _itemsType = type;
        }

        private ItemsType _itemsType;
        /// <summary>
        /// 物品类型
        /// </summary>
        public ItemsType ItemsType { get { return _itemsType; } set { _itemsType = value; } }

        /// <summary>
        /// 物品名称
        /// </summary>
        public String ItemsName { get { return GetItemsTypeName(_itemsType); } }

        /// <summary>
        /// 物品图片
        /// </summary>
        public String Image { get; set; }

        /// <summary>
        /// 根据物品类型获得物品名称
        /// </summary>
        /// <param name="itemsType"></param>
        /// <returns></returns>
        private string GetItemsTypeName(ItemsType itemsType)
        {
            switch (ItemsType)
            {
                case ItemsType.AmuletsLeft:
                    return "左手戒指";
                case ItemsType.AmuletsRight:
                    return "右手戒指";
                case ItemsType.Feet:
                    return "鞋子";
                case ItemsType.Hands:
                    return "手套";
                case ItemsType.Head:
                    return "头盔";
                case ItemsType.Legs:
                    return "裤子";
                case ItemsType.OffHand:
                    return "副手";
                case ItemsType.Rings:
                    return "护身符";
                case ItemsType.Shoulders:
                    return "护肩";
                case ItemsType.Torso:
                    return "胸甲";
                case ItemsType.Waist:
                    return "腰带";
                case ItemsType.Weapons:
                    return "武器";
                case ItemsType.Wrists:
                    return "护腕";
                default:
                    return "";
            }
        }

        private List<ItemsProperty> _properties;
        /// <summary>
        /// 装备属性列表
        /// </summary>
        [XmlArray()]
        public List<ItemsProperty> Properties
        {
            get
            {
                return _properties;
            }
        }

        #region IAffecteDexterity 成员

        double IAffecteDexterity.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteDexterity iaffecte = p as IAffecteDexterity;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteIntelligence 成员

        double IAffecteIntelligence.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteIntelligence iaffecte = p as IAffecteIntelligence;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteStrength 成员

        double IAffecteStrength.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteStrength iaffecte = p as IAffecteStrength;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteVitality 成员

        double IAffecteVitality.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteVitality iaffecte = p as IAffecteVitality;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteLifePercent 成员

        double IAffecteLifePercent.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteLifePercent iaffecte = p as IAffecteLifePercent;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteArmor 成员

        double IAffecteArmor.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteArmor iaffecte = p as IAffecteArmor;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteArcaneHolyResistance 成员

        double IAffecteArcaneHolyResistance.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteArcaneHolyResistance iaffecte = p as IAffecteArcaneHolyResistance;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteColdResistance 成员

        double IAffecteColdResistance.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteColdResistance iaffecte = p as IAffecteColdResistance;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteFireResistance 成员

        double IAffecteFireResistance.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteFireResistance iaffecte = p as IAffecteFireResistance;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteLightningResistance 成员

        double IAffecteLightningResistance.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteLightningResistance iaffecte = p as IAffecteLightningResistance;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffectePhysicalResistance 成员

        double IAffectePhysicalResistance.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffectePhysicalResistance iaffecte = p as IAffectePhysicalResistance;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffectePoisonResistance 成员

        double IAffectePoisonResistance.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffectePoisonResistance iaffecte = p as IAffectePoisonResistance;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteBlockChance 成员

        double IAffecteBlockChance.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteBlockChance iaffecte = p as IAffecteBlockChance;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteBlockValue 成员

        double IAffecteBlockValue.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteBlockValue iaffecte = p as IAffecteBlockValue;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteBlockValue 成员


        double IAffecteBlockValue.AffecteMax(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteBlockValue iaffecte = p as IAffecteBlockValue;
                if (iaffecte != null) returnValue = iaffecte.AffecteMax(returnValue);
            }

            return returnValue;
        }

        double IAffecteBlockValue.AffecteMin(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteBlockValue iaffecte = p as IAffecteBlockValue;
                if (iaffecte != null) returnValue = iaffecte.AffecteMin(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteMeleeDamageReduction 成员

        double IAffecteMeleeDamageReduction.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteMeleeDamageReduction iaffecte = p as IAffecteMeleeDamageReduction;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteMissileDamageReduction 成员

        double IAffecteMissileDamageReduction.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteMissileDamageReduction iaffecte = p as IAffecteMissileDamageReduction;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteMinDamage 成员

        double IAffecteMinDamage.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteMinDamage iaffecte = p as IAffecteMinDamage;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteMaxDamage 成员

        double IAffecteMaxDamage.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteMaxDamage iaffecte = p as IAffecteMaxDamage;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteAttackSpeed 成员

        double IAffecteAttackSpeed.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteAttackSpeed iaffecte = p as IAffecteAttackSpeed;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteAttackSpeedPercent 成员

        double IAffecteAttackSpeedPercent.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteAttackSpeedPercent iaffecte = p as IAffecteAttackSpeedPercent;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteCriticalHitChance 成员

        double IAffecteCriticalHitChance.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteCriticalHitChance iaffecte = p as IAffecteCriticalHitChance;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteCriticalHitDamage 成员

        double IAffecteCriticalHitDamage.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteCriticalHitDamage iaffecte = p as IAffecteCriticalHitDamage;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteLifePerHit 成员

        double IAffecteLifePerHit.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteLifePerHit iaffecte = p as IAffecteLifePerHit;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteLifePerKill 成员

        double IAffecteLifePerKill.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteLifePerKill iaffecte = p as IAffecteLifePerKill;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteLifePerSecond 成员

        double IAffecteLifePerSecond.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteLifePerSecond iaffecte = p as IAffecteLifePerSecond;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteLifeSteal 成员

        double IAffecteLifeSteal.Affecte(double source)
        {
            Double returnValue = source;

            foreach (ItemsProperty p in Properties)
            {
                IAffecteLifeSteal iaffecte = p as IAffecteLifeSteal;
                if (iaffecte != null) returnValue = iaffecte.Affecte(returnValue);
            }

            return returnValue;
        }

        #endregion

        #region IAffecteShowDamage 成员

        double IAffecteShowDamage.GetShowDamage()
        {
            foreach (ItemsProperty p in Properties)
            {
                IAffecteShowDamage iaffecte = p as IAffecteShowDamage;
                return iaffecte.GetShowDamage();
            }

            return 0;
        }

        #endregion
    }
}
